package fire.database;

public class FieldType {
	public static final int STRING_INT = 1;
	public static final int INTEGRE_INT = 2;
	public static final int LONG_INT = 3;
	public static final int DOUBLE_INT = 4;
	public static final int DATE_INT = 5;
	public static final int CLOB_INT = 6;
	public static final int BLOB_INT = 7;
	public static final FieldType STRING = new FieldType(1, "String",
			Boolean.valueOf(false), "", "VARCHAR");

	public static final FieldType INTEGER = new FieldType(2, "Integer",
			Boolean.valueOf(false), "", "INTEGER");

	public static final FieldType LONG = new FieldType(3, "Long",
			Boolean.valueOf(false), "", "BIGINT");

	public static final FieldType DOUBLE = new FieldType(4, "Double",
			Boolean.valueOf(false), "", "DOUBLE");

	public static final FieldType DATE = new FieldType(5, "Date",
			Boolean.valueOf(true), "java.util.Date", "TIME");

	public static final FieldType CLOB = new FieldType(6, "String",
			Boolean.valueOf(false), "", "VARCHAR");

	public static final FieldType BLOB = new FieldType(7, "Blob",
			Boolean.valueOf(true), "java.sql.Blob;", "VARBINARY");
	private transient int type;
	private transient String typeName;
	private transient Boolean needImportType;
	private transient String importType;
	private transient String jdbcType;

	private FieldType(int type, String typeName, Boolean needImportType,
			String importType, String jdbcType) {
		this.type = type;
		this.typeName = typeName;
		this.needImportType = needImportType;
		this.importType = importType;
		this.jdbcType = jdbcType;
	}

	public boolean equals(Object obj) {
		if (((obj instanceof FieldType))
				&& (((FieldType) obj).type == this.type)) {
			return true;
		}
		return false;
	}

	public int getType() {
		return this.type;
	}

	public String getTypeName() {
		return this.typeName;
	}

	public Boolean getNeedImportType() {
		return this.needImportType;
	}

	public String getImportType() {
		return this.importType;
	}

	public static FieldType toFieldType4SqlServer(String fieldType) {
		return null;
	}

	public static FieldType toFieldType4Oralce(String fieldType) {
		String typeTmp = fieldType.toUpperCase();
		if ((typeTmp.equals("VARCHAR2")) || (typeTmp.equals("VARCHAR"))
				|| (typeTmp.equals("CHAR"))) {
			return STRING;
		}
		if (typeTmp.equals("INTEGER")) {
			return INTEGER;
		}
		if (typeTmp.equals("LONG")) {
			return LONG;
		}
		if (typeTmp.equals("DOUBLE")) {
			return DOUBLE;
		}
		if (typeTmp.equals("DATE")) {
			return DATE;
		}
		if ((typeTmp.equals("CLOB")) || (typeTmp.equals("NCLOB"))) {
			return CLOB;
		}
		if ((typeTmp.equals("BLOB")) || (typeTmp.equals("NBLOB"))) {
			return BLOB;
		}
		return STRING;
	}

	public String getJdbcType() {
		return this.jdbcType;
	}
}
